import {createRouter, createWebHashHistory, RouteRecordRaw} from 'vue-router'

const routes: Array<RouteRecordRaw> = [
    // 学生端
    {
        path: '/home',
        name: 'home',
        redirect: '/index',
        component: () => import('../views/Home.vue'),
        children: [
            {path: '/class',name:"class", component: () => import('../views/ChooseClassAll.vue')},
            {path: '/chapter',name:"chapter", component: () => import('../views/Chapter.vue')},
            {path: '/index',name:"index", component: () => import('../views/Index.vue')},
            {path: '/codeEdit', name: '/codeEdit', component: () => import('../views/CodeEditView.vue')},
            {path: '/shiyanContent', name: 'shiyanContent', component: () => import('../views/ExperimentContent.vue')},
            {path: '/standard', name: 'standard', component: () => import('../views/ScoreStandard.vue')},
            {path: '/upload', name: 'upload', component: () => import('../views/UploadReport.vue')},
            {path: '/runcode', name: 'runcode', component: () => import('../views/RunCode.vue')},
            {path: '/onlinejudge', name: 'onlinejudge', component: () => import('../views/OnlineJudge.vue')},
            {path: '/userinfo', name: 'userinfo', component: () => import('../views/UserInfoView.vue')},
        ]
    },
    //  管理员
    {
        path: '/notice',name:'notice', component: () => import('../views/admin/notice.vue'),
    },
    {
        path: '/studentmanage',name:'studentmanage', component: () => import('../views/admin/StudentManager.vue'),
    },
    {
        path: '/coursemanage',name:'coursemanage', component: () => import('../views/admin/CourseManager.vue'),
    },
    {
        path: '/teachermanage',name:'teachermanage', component: () => import('../views/admin/TeacherManager.vue'),
    },

    //注册登录
    {
        path: '/login',name:'login', component: () => import('../views/login.vue')
    },
    {
        path: '/register',name:'register', component: () => import('../views/register.vue')
    },

    //教师端
    {
        path: '/thome',
        name: 'thome',
        redirect: '/tindex',
        component: () => import('../views/teacher/TeacherIndex.vue'),
        children: [
            {path: '/tclass', component: () => import('../views/teacher/ChooseClassAll.vue')},
            {path: '/tchapter', component: () => import('../views/teacher/TeacherChapter.vue')},
            {path: '/tindex', component: () => import('../views/teacher/Index.vue')},
            {path: '/tuserinfo', component: () => import('../views/UserInfoView.vue')},
            {path: '/grade', component: () => import('../views/teacher/Grade.vue')},
            {path: '/download', component: () => import('../views/teacher/Experiment.vue')},
        ]
    },
    {
        path: '/test',
        name: 'test',
        component: () => import('../views/teacher/DownStuExp.vue'),
    },

]

const router = createRouter({
    history: createWebHashHistory(process.env.BASE_URL),
    routes
})

// 路由拦截
// router.beforeEach((to, from, next) => {
//     if (to.path == '/login' || to.path == '/register') {
//         // 登录或者注册才可以往下进行
//         next();
//     } else {
//         // 获取 token
//         const token = localStorage.getItem('Authorization');
//         // token 不存在
//         if (token === null || token === '') {
//             ElMessage.error('您还没有登录，请先登录');
//             next('/login');
//         } else {
//             next();
//         }
//     }
// });


export default router
